﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteMaster.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="Microhard.Framework.MVCHelper" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    门店销量查询
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="section-header">
        <div class="title">
            <img src="<%=Url.Content("~/Content/images/ico-catalog.png")%>" alt="" />
            门店销量查询
        </div>
        <div class="options">
        </div>
    </div>
    <table width="100%">
        <tr>
            <td class="adminTitle">
                <img alt="客户" src="<%=Url.Content("~/Content/images/ico-help.gif") %>" title="客户"></img><label
                    for="operationName" title="客户">客户</label>:
            </td>
            <td class="adminData">
                <%Html.RenderAction("GetKAList", "FMCGTool",
                      new
                      {
                          ctrAttr = new Microhard.WebUI.Models.AttriubteOfSelectList { ParameterModelName = "SelectedKAID", IsMulitiplySelect = false, DefaultSelectedText = "请选择", DefaultSelectedValue = Guid.Empty.ToString() },
                          area = "Tools"
                      });%>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                <img alt="开始时间" src="<%=Url.Content("~/Content/images/ico-help.gif") %>" title="开始时间"></img><label
                    for="operationName" title="开始时间">开始时间</label>:
            </td>
            <td class="adminData">
                <%=Html.Telerik().DatePicker().Name("beginDate") %>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                <img alt="结束时间" src="<%=Url.Content("~/Content/images/ico-help.gif") %>" title="结束时间"></img><label
                    for="operationName" title="结束时间">结束时间</label>:
            </td>
            <td class="adminData">
                <%=Html.Telerik().DatePicker().Name("endDate") %>
            </td>
        </tr>
    </table>
    <p>
    </p>
    <table class="adminContent">
        <tr>
            <td>
                <%Html.Telerik().Grid<Micrhard.FMCG.Server.Models.SubKAModel>((List<Micrhard.FMCG.Server.Models.SubKAModel>)this.Model.Data)
                    .Name("operation-grid")
                    .ToolBar(t => t.Template(g =>
                    { %>
                <%var searchParms = new Dictionary<string, string>();
                  searchParms.Add("KAID", "SelectedKAID");
                  searchParms.Add("ReportQueryForBeginDate", "beginDate");
                  searchParms.Add("ReportQueryForEndDate", "endDate");
                %>
                <div class="header-menu">
                    <ul class="t-widget t-reset t-header t-menu">
                        <li class="t-item  t-state-default">
                            <%=Html.Authorized_SearchButton("btnSearch", "查询", "operation-grid", searchParms, "OperationGridOnGridDataBinding")%>
                        </li>
                        <li class="t-item  t-state-default" id="totalStoreCount"></li>
                        <li class="t-item  t-state-default" id="totalAmount"></li>
                    </ul>
                </div>
                <%}))
                         .ClientEvents(events => events.OnDataBinding("OperationGridOnGridDataBinding").OnComplete("dataCmp"))
                         .Columns(columns =>
                    {
                        columns.Bound(x => x.CustomerCode).Title("编号");
                        columns.Bound(x => x.Name).Title("门店名称");
                        columns.Template(x => {%>
                <a href="javascript:void(0)" onclick="showDetail('<%=x.SubID %>','<%=x.QueryBeginDateForDetail %>','<%=x.QueryEndDateForDetail %>','<%=x.KACode %>')">
                    <%=x.AmountSaleVolumn %></a>
                <%}).ClientTemplate("<a href='javascript:void(0)' onclick=showDetail('<#= SubID #>','<#= QueryBeginDateForDetail #>','<#= QueryEndDateForDetail #>','<#= KACode #>')><#= AmountSaleVolumn #></a>").Title("销量(元)");

                        columns.Bound(x => x.SaleCount).Title("销售数量");
                        columns.Bound(x => x.HBAmountSaleVolumn).Title("环比(元)");
                        columns.Bound(x => x.HB).Title("环比增长(%)");
                        columns.Bound(x => x.TBAmountSaleVolumn).Title("同比(元)");
                        columns.Bound(x => x.TB).Title("同比增长(%)");
                    })
                    .DataBinding(dataBinding => dataBinding.Ajax().Select("_ListWithNoPaging", "SaleVolumn"))
                    .EnableCustomBinding(true)
                    .Render();
                %>
            </td>
        </tr>
    </table>
    <% Html.Telerik().Window()
           .Name("detail")
           .Draggable(true)
           .Scrollable(true)
           .Modal(false)
           .Visible(false)
           .Height(200)
           .Width(400)
           .Render();
    %>
    <script type="text/javascript">
        function showDetail(subkaid, begin, end, sys) {
            $.get("GetProductSaledDetailOfDay", { identity: subkaid, fromdate: begin, enddate: end, sys: sys },
                              function (data) {
                                  if (data.length > 0) {
                                      //生成html
                                      var html = "";
                                      for (var i = 0; i < data.length; i++) {
                                          html += "<tr><td>" + data[i].ProductName + "</td><td>&nbsp;</td><td>" + data[i].SaleVolumn + "</td></tr>";
                                      }
                                      var window = $('#detail').data('tWindow');
                                      window.content("<table>" + html + "</table>");
                                      if (data[0].StoreCode != null && data[0].StoreName != null) {
                                          window.title("编号:" + data[0].StoreCode + " 名称:" + data[0].StoreName);
                                      }
                                      else {
                                          window.title("产品数量:" + data.length);
                                      }
                                      window.center();
                                      window.open();
                                  }
                              });
        }
        function dataCmp(data) {
            var result = data.response;
            var storeInfo = "<span>门店数量:" + result.Data.length + "<span>";
            $("#totalStoreCount").html(storeInfo);
        }
    </script>
</asp:Content>
